import {type Action, ActionTypes, type CounterState} from "./state.ts";

export const CounterReducer =
    (state: CounterState, action: Action): CounterState => {
    switch (action.type) {
        case ActionTypes.INCREMENT:
            return { count: state.count + 1 };
        case ActionTypes.DECREMENT:
            return { count: state.count - 1 };
        case ActionTypes.RESET:
            return { count: 0 };
        default:
            return state;
    }
}